home *** CD-ROM | disk | FTP | other *** search
- ///////////////////////////////////////////////////////////////////////////////
- // $Id: Event.hxx,v 1.1 1994/02/18 19:49:44 bmott Exp $
- ///////////////////////////////////////////////////////////////////////////////
- // Event.hxx
- //
- // This class maintains a queue of events requested by EventBase derived
- // objects.
- //
- //
- // BSVC "A Microprocessor Simulation Framework"
- // Copyright (c) 1993
- // By: Bradford W. Mott
- // August 11,1993
- //
- ///////////////////////////////////////////////////////////////////////////////
- // $Log: Event.hxx,v $
- // Revision 1.1 1994/02/18 19:49:44 bmott
- // Initial revision
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #ifndef EVENT_HXX
- #define EVENT_HXX
-
- class EventHandler;
-
- ///////////////////////////////////////////////////////////////////////////////
- // This should be the base class for any class that is going to register
- // events with the event handler.
- ///////////////////////////////////////////////////////////////////////////////
- class EventBase {
- private:
- EventHandler* event_handler;
-
- public:
- EventBase(EventHandler* h)
- : event_handler(h)
- {}
-
- virtual ~EventBase();
-
- virtual void EventCallback(long data, void* pointer)=0;
- };
-
- ///////////////////////////////////////////////////////////////////////////////
- // This class manages a list of time events. When the time expires for
- // an event the EventCallback() for the associate object is called
- ///////////////////////////////////////////////////////////////////////////////
- class EventHandler {
- private:
-
- // The event class
- class Event {
- private:
- // The object that owns this event
- EventBase* object;
-
- // Data passed to the callback routine
- void* pointer;
- long data;
-
- public:
- Event(EventBase* o, long d, void* p, unsigned long t)
- : object(o), data(d), pointer(p),
- total_time(t),
- next((void *)0)
- {};
-
- // Dispatch the event by calling the object's callback routine
- inline void Dispatch()
- { object->EventCallback(data, pointer); }
-
- // Return the owning object
- inline EventBase* Owner()
- { return(object); }
-
- // Total amount of time to elapse before the event
- const long total_time;
-
- // Time left before the event occurs
- long delta_time;
-
- // Pointer to the next event
- Event *next;
- };
-
- // Linked list of events
- Event *list;
-
- // Number of calls since last time update
- long iterations;
-
- // Last usec_per_check update time
- long old_time;
-
- // Average micro-seconds per call to Check
- long usec_per_check;
-
- public:
- EventHandler();
-
- // Check for any expired events
- void Check();
-
- // Add an event to the event list
- void Add(EventBase* object, long data, void* pointer, long time);
-
- // Remove events for the given object
- void Remove(EventBase* object);
- };
-
- #endif
-